# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=remake
_autotools=yes
pkgbase=mingw-w64-${_realname}-git
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
_ver_base=4.1
pkgver=4.1.2943.f059924
pkgrel=1
pkgdesc="Enhanced GNU Make - tracing, error reporting, debugging, profiling and more (mingw-w64)"
arch=('any')
url="https://github.com/rocky/remake"
license=('GPL3')
provides=("${MINGW_PACKAGE_PREFIX}-remake")
conflicts=("${MINGW_PACKAGE_PREFIX}-remake")
options=('debug' '!strip')
depends=("${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=('git'
             'wget')
source=("${_realname}"::"git+https://github.com/rocky/${_realname}#branch=master"
        'make-getopt.patch'
        'make-linebuf-mingw.patch')
sha256sums=('SKIP'
            '6aa89d99b37de75f90e79941f8142f388ce30740ab591bcb025f0eadce54011f'
            '11859c48a641baf9a5f000fa4e5c10d0cdf602bc8e3aaea3ed74005943dcd8da')

pkgver() {
  cd "${srcdir}"/${_realname}
  printf "%s.%s.%s" "$_ver_base" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${srcdir}/${_realname}
  patch -p1 -i ${srcdir}/make-getopt.patch
  patch -p1 -i ${srcdir}/make-linebuf-mingw.patch
  if [[ "${_autotools}" = "yes" ]]; then
    autoreconf -fi
  fi
}

build() {
  if [[ "${_autotools}" = "yes" ]]; then
      [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
      mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}
      ../${_realname}/configure \
      --prefix=${MINGW_PREFIX} \
      --host=${MINGW_CHOST} \
      --without-libintl-prefix \
      --without-libiconv-prefix \
      ac_cv_dos_paths=yes
    make -j1 scm-update do-po-update all remake
  else
    cmd /c 'build_w32.bat --without-guile gcc'
  fi
}

package() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}/{bin,lib,include}
  if [[ "${_autotools}" = "yes" ]]; then
    cd ${srcdir}/build-${MINGW_CHOST}
    cp -f make.exe ${pkgdir}${MINGW_PREFIX}/bin/mingw32-remake.exe
  else
    cd ${srcdir}/${_realname}
    cp -f gnumake.exe ${pkgdir}${MINGW_PREFIX}/bin/mingw32-remake.exe
    cp -f libgnumake-1.dll.a ${pkgdir}${MINGW_PREFIX}/lib/
    cp -f gnumake.h ${pkgdir}${MINGW_PREFIX}/include/
  fi
}
